
#ifndef _MEMBER_BTextEdit_H_
#define _MEMBER_BTextEdit_H_

#include <time.h>
#include <BMap>
#include <BColor>
#include <BRect>
#include <BClock>
#include <BPoint>
#include <BString>
#include <BStaticArray>
#include <BRange>
#include <BTextEdit>
#include <BPainter>
#include "ITextBlock.h"

namespace BWE
{
	typedef BList<ITextBlock>::iterator TextBlockIterator;

	class member_BTextEdit
	{
	public:
		member_BTextEdit(BTextEdit* textEdit);
		~member_BTextEdit();

		void initBlocks();
		void appendBlocks(const BString& str);
		void adjustBlocks();
		void updateHover(const BPoint& pos);
		void updateLineNumbers();

		void selectWord();
		void selectBlocks();
		void unselected();

		bool seekPrevWord();
		bool seekNextWord();
		bool seekPrev();
		bool seekNext();
		bool remove();
		bool input(BCode code);
		bool input(const BString& text);

		void paintSelection(BPainter& painter);
		void paintCursor(BPainter& painter);
		
		BTextEdit*			boss;
		BString				text;
		int					lineHeight;
		bool				lineShown;
		bool				wordWrap;
		clock_t				blinkTick;
		int					blinkTime;
		bool				readOnly;
		bool				changed;

		TextBlockIterator	hoverBlock;
		int					hoverIndex;
		TextBlockIterator	inputBlock;
		int					inputIndex;
		bool				inputShown;

		bool				selected;
		int					pressed;
		BPoint				pressPoint;
		int					pressIndex;
		TextBlockIterator	beginBlock;
		int					beginIndex;
		TextBlockIterator	endBlock;
		int					endIndex;

		TextBlockIterator	showFirst;
		TextBlockIterator	showLast;
		BList<ITextBlock>	blocks;
	};
}

#endif